package itheima.d02;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

public class ReceiveThread extends Thread {

    Socket socket;

    public ReceiveThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try (
                //1.获取Socket的输入流对象
                InputStream is = socket.getInputStream();
                BufferedReader br = new BufferedReader(new InputStreamReader(is));
        ) {
            while(true){
                String msg = br.readLine();
                System.out.println("server"+msg);

                if(msg == null){
                    break;
                }
            }

        } catch (Exception e) {
            System.out.println("客户端已退出...");
        }

    }
}
